package com.tl.khadmin.service.impl;
  
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.poi.hssf.util.HSSFColor.RED;
import org.springframework.stereotype.Service;

import com.tl.khadmin.bean.OrderAftersale;
import com.tl.khadmin.bean.OrderRefund;
import com.tl.khadmin.bean.SettlementBill;
import com.tl.khadmin.bean.Staff;
import com.tl.khadmin.bean.Supplier;
import com.tl.khadmin.mapper.OrderRefundMapper;
import com.tl.khadmin.page.Page;
import com.tl.khadmin.service.OrderRefundIService;
import com.tl.khadmin.util.CommonUtil;
import com.tl.khadmin.util.Constant;
import com.tl.khadmin.util.PutParamUtil;  

@Service
public class OrderRefundServiceImpl implements OrderRefundIService{
	
	@Resource
	private OrderRefundMapper orderRefundMapper;
	
	/**
	 * 操作退款
	 */
	@Override
	public String transfer(HttpSession session, Integer id) {
		OrderRefund ore = new OrderRefund();
		Supplier supplier = (Supplier) session.getAttribute(Constant.USER_SUPPLIER);
		if(supplier.getIsInterior() != 1) {
			return CommonUtil.returnMapResultToJson("fail", "无权限");
		}
		ore.setId(id);
		ore.setRefundStatus(3);
		ore.setRefundTime(new Date());  
		return CommonUtil.returnMapResultByRows(orderRefundMapper.updateByPrimaryKeySelective(ore), 
				"提交成功", "提交失败");
	}
	
	public List<OrderRefund> listOrderRefund(Map<String, Object> param){
		return orderRefundMapper.listOrderRefund(param); 
	}
	
	@Override
	public Page<OrderRefund> showOrderRefundByPage(HttpSession session, Integer pageNum, 
			Integer pageSize, Map<String, Object> params) {
		Page<OrderRefund> page=new Page<OrderRefund>(pageNum, pageSize);
        params.put("page", page);   
        Supplier supplier = (Supplier) session.getAttribute(Constant.USER_SUPPLIER);
        PutParamUtil.setParamIsInterior(supplier, params);	//设置查询供应商数据范围 
        List<OrderRefund> list= orderRefundMapper.showOrderRefundByPage(params);  
		page.setResult(list);
		return page;
	}

	@Override
	public String audit(HttpSession session, OrderRefund orderRefund) { 
		OrderRefund ore = new OrderRefund();
		Staff staff = (Staff) session.getAttribute(Constant.USER); 
		ore.setAuditId(staff.getId());
		ore.setAuditTime(new Date());
		ore.setAuditStatus(orderRefund.getAuditStatus());
		ore.setRemark(orderRefund.getRemark());
		ore.setId(orderRefund.getId());
		int result = orderRefundMapper.updateByPrimaryKeySelective(ore); 
		return CommonUtil.returnMapResultByRows(result, "提交成功", "提交失败，请重试"); 
	}
	
}
